/*
 * CategoriesDetailForm_View.java
 * Dibuat untuk percontohan final project mata kuliah
 * Pemrograman Lanjut yang diampu oleh M. Fairul Filza, M.Kom
 * STMIK AMIKOM Yogyakarta Tempat Kuliah Orang Berdasi
 * Created on 21 Oct 2013, 08:45:19
 */

package Views;

// <editor-fold defaultstate="collapsed" desc="Import Code">
import Controllers.MasterCd_Controller;
import Interfaces.ViewsProcess_Interface;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.table.DefaultTableModel;
// </editor-fold>

/** @author FaiFilza@Amikom.ac.id */
public class MasterCd_View extends JPanel implements ViewsProcess_Interface {
    // Class Attribute
    private ImageIcon Image;

    // <editor-fold defaultstate="collapsed" desc="Layout Attribute">
    // Initialize Component Panel
    
    private JButton BtnEdit;
    private JButton BtnDelete;
    private JButton BtnNew;
    private JButton BtnRefresh;
    private JLabel LblCode;
    private MainMenu_MainView main;
    private JScrollPane ScrTable;
    private JTable TblData;
    private boolean Search;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Constructor Code">
    public MasterCd_View(MainMenu_MainView main) {
        main = main;
        BtnEdit = new JButton();
        BtnDelete = new JButton();
        BtnNew = new JButton();
        BtnRefresh = new JButton();
        LblCode = new JLabel();
        TblData = new JTable();
        ScrTable = new JScrollPane();
        Search = false;
        initComponents();
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Getter and Setter Code">
    
    public MainMenu_MainView getMain(){
        return main;
    }
    
    public JLabel getLblCode() {
        return LblCode;
    }

    public void setLblCode(JLabel LblCode) {
        this.LblCode = LblCode;
    }
    
    public JButton getBtnEdit(){
        return BtnEdit;
    }
    public void setBtnEdit(JButton BtnEdit){
        this.BtnEdit = BtnEdit;
    }
    public JButton getBtnDelete(){
        return BtnDelete;
    }
    public void setBtnDelete(JButton BtnDelete){
        this.BtnDelete = BtnDelete;
    }
    public JButton getBtnNew(){
        return BtnNew;
    }
    public void setBtnNew(JButton BtnNew){
        this.BtnNew = BtnNew;
    }
    public JButton getBtnRefresh(){
        return BtnRefresh;
    }
    public void setBtnRefresh(JButton BtnRefresh){
        this.BtnRefresh = BtnRefresh;
    }
    public JScrollPane getScrTable() {
        return ScrTable;
    }

    public void setScrTable(JScrollPane ScrTable) {
        this.ScrTable = ScrTable;
    }
     public JTable getTblData() {
        return TblData;
    }

    public void setTblData(JTable TblData) {
        this.TblData = TblData;
    }
    public void setSearch(boolean Search){
        this.Search = Search;
    }
    public boolean  isSearch(){
        return Search;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Method Code">
//    public JPanel pnlEntities() {
//        JPanel Panel = new JPanel();
//        Font FontStyle = new Font("Tahoma", 1, 12);
//
//        Panel.setLayout(null);
//        Panel.setBackground(new Color(0, 0, 0));
//        Panel.setOpaque(true);
//    
//        TblData.setModel(new DefaultTableModel(
//            new Object [][] {
//
//            },
//            new String [] {
//
//            }
//        ){
//            @Override
//            public boolean isCellEditable(int row, int column) {
//            //Only the third column
//            return false;
//        }
//        });
//        ScrTable.setViewportView(TblData);
//        Panel.add(ScrTable);
//        ScrTable.setBounds(139, 163, 847, 402);
//
//        LblCode.setFont(FontStyle);
//        LblCode.setText(null);
//        LblCode.setVisible(false);
//        Panel.add(LblCode);
//        LblCode.setBounds(35, 110, 200, 20);
//        
//        BtnNew.setOpaque(false);
//        BtnNew.setBorderPainted(false);
//        BtnNew.setContentAreaFilled(false);
//        BtnNew.setBorder(null);
//        BtnNew.setVisible(true);
//        Panel.add(BtnNew);
//        BtnNew.setBounds(7,167,118,35);
//        
//        BtnEdit.setOpaque(false);
//        BtnEdit.setBorderPainted(false);
//        BtnEdit.setContentAreaFilled(false);
//        BtnEdit.setBorder(null);
//        BtnEdit.setVisible(true);
//        BtnEdit.setEnabled(false);
//        Panel.add(BtnEdit);
//        BtnEdit.setBounds(7,272,118,35);
//        
//        BtnDelete.setOpaque(false);
//        BtnDelete.setBorderPainted(false);
//        BtnDelete.setContentAreaFilled(false);
//        BtnDelete.setBorder(null);
//        BtnDelete.setVisible(true);
//        BtnDelete.setEnabled(false);
//        Panel.add(BtnDelete);
//        BtnDelete.setBounds(7,325,118,35);
//        
//        BtnRefresh.setOpaque(false);
//        BtnRefresh.setBorderPainted(false);
//        BtnRefresh.setContentAreaFilled(false);
//        BtnRefresh.setBorder(null);
//        BtnRefresh.setVisible(true);
//        Panel.add(BtnRefresh);
//        BtnRefresh.setBounds(7,220,118,35);
//        
//        // Context Panel
//        //Panel.setLayout(null);
//        //Panel.setBackground(new Color(0, 250, 250));
//        //Panel.setOpaque(true);
//        //Panel.setVisible(true);
//        //Panel.add(getPnlFront());
//        //Pael.setBounds(0, 0, 847, 402);
//
//
//        eventControllers();
//        imageControllers();
//        return Panel;
//    }

    @Override
    public void eventControllers() {
        
        MasterCd_Controller ControlPanel = new MasterCd_Controller(this);
        this.addComponentListener(ControlPanel.ViewComponent_Listener);
        this.addKeyListener(ControlPanel.ViewKey_Listener);
        BtnNew.addActionListener(ControlPanel.ViewButton_Listener);
        BtnNew.addMouseListener(ControlPanel.ViewButtonImg_Listener);
        BtnEdit.addActionListener(ControlPanel.ViewButton_Listener);
        BtnEdit.addMouseListener(ControlPanel.ViewButtonImg_Listener);
        BtnRefresh.addActionListener(ControlPanel.ViewButton_Listener);
        BtnRefresh.addMouseListener(ControlPanel.ViewButtonImg_Listener);
        BtnDelete.addActionListener(ControlPanel.ViewButton_Listener);
        BtnDelete.addMouseListener(ControlPanel.ViewButtonImg_Listener);
        TblData.addMouseListener(ControlPanel.ViewTable_Listener);
        TblData.addKeyListener(ControlPanel.ViewKey_Listener);
        createKeybindings(TblData);
    }

    @Override
    public void imageControllers() {
        Image = new ImageIcon(getClass().getResource("/Images/edit3.png"));
        BtnEdit.setIcon(Image);
        Image = new ImageIcon(getClass().getResource("/Images/delete3.png"));
        BtnDelete.setIcon(Image);
        Image = new ImageIcon(getClass().getResource("/Images/new.png"));
        BtnNew.setIcon(Image);
        Image = new ImageIcon(getClass().getResource("/Images/refresh.png"));
        BtnRefresh.setIcon(Image);
        
    }
    // </editor-fold>

    private void createKeybindings(JTable table) {
        table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
        table.getActionMap().put("Enter", new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                //do something on JTable enter pressed
            }
        });
    }
    
    @Override
    public void initComponents() {
        Font FontStyle = new Font("Tahoma", 1, 12);

        this.setLayout(null);
        this.setBackground(new Color(0, 0, 0));
        this.setOpaque(true);
    
        TblData.setModel(new DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ){
            @Override
            public boolean isCellEditable(int row, int column) {
            //Only the third column
            return false;
        }
        });
        ScrTable.setViewportView(TblData);
//        ScrTable.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.add(ScrTable);
        ScrTable.setBounds(139, 163, 847, 402);

        LblCode.setFont(FontStyle);
        LblCode.setText(null);
        LblCode.setVisible(false);
        this.add(LblCode);
        LblCode.setBounds(35, 110, 200, 20);
        
        BtnNew.setOpaque(false);
        BtnNew.setBorderPainted(false);
        BtnNew.setContentAreaFilled(false);
        BtnNew.setBorder(null);
        BtnNew.setVisible(true);
        BtnNew.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.add(BtnNew);
        BtnNew.setBounds(7,167,118,35);
        
        BtnEdit.setOpaque(false);
        BtnEdit.setBorderPainted(false);
        BtnEdit.setContentAreaFilled(false);
        BtnEdit.setBorder(null);
        BtnEdit.setVisible(true);
        BtnEdit.setEnabled(false);
        BtnEdit.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.add(BtnEdit);
        BtnEdit.setBounds(7,272,118,35);
        
        BtnDelete.setOpaque(false);
        BtnDelete.setBorderPainted(false);
        BtnDelete.setContentAreaFilled(false);
        BtnDelete.setBorder(null);
        BtnDelete.setVisible(true);
        BtnDelete.setEnabled(false);
        BtnDelete.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.add(BtnDelete);
        BtnDelete.setBounds(7,325,118,35);
        
        BtnRefresh.setOpaque(false);
        BtnRefresh.setBorderPainted(false);
        BtnRefresh.setContentAreaFilled(false);
        BtnRefresh.setBorder(null);
        BtnRefresh.setVisible(true);
        BtnRefresh.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.add(BtnRefresh);
        BtnRefresh.setBounds(7,220,118,35);
        
        // Context Panel
        //Panel.setLayout(null);
        //Panel.setBackground(new Color(0, 250, 250));
        //Panel.setOpaque(true);
        //Panel.setVisible(true);
        //Panel.add(getPnlFront());
        //Pael.setBounds(0, 0, 847, 402);


        eventControllers();
        imageControllers();
    }
}